package com.kancy.stream.rabbit.converter;

import org.springframework.amqp.core.Message;
import org.springframework.amqp.core.MessageProperties;
import org.springframework.amqp.support.converter.MessageConversionException;
import org.springframework.lang.Nullable;

import java.lang.reflect.Type;

/**
 * MessageConverter
 *
 * @author kancy
 * @date 2020/3/8 12:51
 */
public interface MessageConverter {

    /**
     * Convert a Java object to a Message.
     */
    Message toMessage(Object object, MessageProperties messageProperties);

    /**
     * Convert a Java object to a Message.
     */
    default Message toMessage(Object object, MessageProperties messageProperties, Type genericType) {

        return toMessage(object, messageProperties);
    }

    /**
     * Convert from a Message to a Java object.
     * @param message the message to convert
     * @return the converted Java object
     * @throws MessageConversionException in case of conversion failure
     */
    Object fromMessage(Message message);

}
